package com.example.safeassistan.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.example.safeassistan.R;

public class PastTestDialog extends Dialog {
    private TextView tvEditCount,tvInCorrectCount,tvUserScore;
    private int editCount=0;//回答的数目
    private int inCorrectCount=0;//回答错误的数目
    private int userScore=0;//用户得分

    private ClickListenerInterface clickListenerInterface;

    public PastTestDialog(Context context,int editCount,int inCorrectCount,int userScore) {
        super(context, R.style.custom_dialog_style);
        this.userScore=userScore;
        this.editCount=editCount;
        this.inCorrectCount=inCorrectCount;
    }

    public interface ClickListenerInterface {
        void doSubmit();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
    }

    private void init() {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        // 设置不显示键盘
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
        setContentView(R.layout.dialog_past_test);
        TextView tvExit=findViewById(R.id.tvExit);
        tvEditCount=findViewById(R.id.tvEditCount);
        tvInCorrectCount=findViewById(R.id.tvInCorrectCount);
        tvUserScore=findViewById(R.id.tvUserScore);
        tvExit.setOnClickListener(new clickListener());

        tvEditCount.setText(".您已经回答了"+editCount+"道题");
        tvInCorrectCount.setText(".答错"+inCorrectCount+"道题");
        tvUserScore.setText(".考试得分"+userScore+"分");
        this.setCancelable(true);
        this.setCanceledOnTouchOutside(true);
    }

    public void setClicklistener(ClickListenerInterface clickListener) {
        clickListenerInterface = clickListener;
    }

    private class clickListener implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.tvExit:
                    clickListenerInterface.doSubmit();
                    break;
            }
        }
    }
}